package cn.com.bluemoon.daps.api.sys.factory;

import cn.com.bluemoon.daps.api.sys.RemoteSysConfigService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.system.entity.DapSystemConfigSandbox;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteSysConfigServiceFallbackFactory implements FallbackFactory<RemoteSysConfigService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSysConfigServiceFallbackFactory.class);


    @Override
    public RemoteSysConfigService create(Throwable throwable) {
        log.error("系统配置服务调用失败:{}", throwable.getMessage());
        return new RemoteSysConfigService() {

            @Override
            public ResultBean<DapSystemConfigSandbox> sandboxConfig() {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统配置信息失败！");
            }
        };
    }
}
